package com.java01.swt.dialog;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

public class Snippet1 extends Shell {

	public static void main(String args[]) {
		try {
			Display display = Display.getDefault();
			Snippet1 shell = new Snippet1(display, SWT.SHELL_TRIM);
			shell.open();
			shell.layout();
			shell.showMessageBox("Java01 Snippets", "Do you visit www.java01.com today?");

			while (!shell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public Snippet1(Display display, int style) {
		super(display, style);
		setSize(300, 200);
	}

	public boolean showMessageBox(String title, String message){
		MessageBox messageBox = new MessageBox(this, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
		messageBox.setText(title);
		messageBox.setMessage(message);
		int response = messageBox.open();
		return response == SWT.YES;
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
